package itsm.isperp.module.service.app;

import itsm.isperp.framework.service.TreeNodeService;
import itsm.isperp.framework.web.request.JqGridFilterRuleOp;
import itsm.isperp.framework.web.request.JqGridRequest;
import itsm.isperp.module.entity.app.AppSystemHelp;
import itsm.isperp.module.repository.app.AppSystemHelpMapper;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

/**
 * 系统帮助的服务
 * 
 * @author lizx
 * @date 2013-7-27
 */
@Service
public class AppSystemHelpService extends TreeNodeService<AppSystemHelp> {

	@Resource
	protected AppSystemHelpMapper appSystemHelpMapper;

	@Override
	public AppSystemHelpMapper getRepository() {
		return this.appSystemHelpMapper;
	}

	/**
	 * 根据编号获取帮助
	 * 
	 * @param code
	 *            唯一编号
	 * @return 系统帮助实体 {@link AppSystemHelp}
	 */
	public AppSystemHelp getByCode(String code) {
		return this.getRepository().findByCode(code);
	}

	/**
	 * 根据编号获取此编号下所有的直接子节点
	 * 
	 * @param code
	 *            唯一编号
	 * @return 系统帮助实体 {@link AppSystemHelp}的列表
	 */
	public List<AppSystemHelp> getUserHelpList() {
		return this
				.getRepository()
				.findChildren(
						new JqGridRequest()
								.isPageable(false)
								.setSelectColumns(
										"id,code,name,treenode_name_path")
								.addFilterRule("parent_code",
										JqGridFilterRuleOp.eq, "USER")
										.setSort("order_num", Direction.ASC))
				.getContent();
	}

}
